Add poweroff and get current position to garmin.
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Mon, 23 Feb 2004 03:27:06 +0000 (03:27 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Mon, 23 Feb 2004 03:27:06 +0000 (03:27 +0000)
gpsbabel/garmin.c
gpsbabel/jeeps/gpscom.c

index cffe483bdd96d5d035125cd36286b526c8723f90..f23f7075f221da646cb12e2ac45a45c259293518 100644 (file)
@@ -1,7 +1,7 @@
 /*
     Jeeps wrapper for Garmin serial protocol.
   
-    Copyright (C) 2002 Robert Lipe, robertlipe@usa.net
+    Copyright (C) 2002, 2003, 2004 Robert Lipe, robertlipe@usa.net
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -32,6 +32,15 @@ static GPS_PWay *tx_routelist;
 static GPS_PWay *cur_tx_routelist_entry;
 static GPS_PTrack *tx_tracklist;
 static GPS_PTrack *cur_tx_tracklist_entry;
+static char *getposn;
+static char *poweroff;
+
+static
+arglist_t garmin_args[] = {
+       { "get_posn", &getposn, "Return current position as a waypoint", ARGTYPE_BOOL},
+       { "power_off", &poweroff, "Command unit to power itself down", ARGTYPE_BOOL},
+       { 0, 0, 0, 0}
+};
 
 static void
 rw_init(const char *fname)
@@ -50,6 +59,11 @@ rw_init(const char *fname)
        }
        GPS_Enable_Error();
 
+       if (poweroff) {
+               GPS_Command_Off(fname);
+               return;
+       }
+
         if (GPS_Init(fname) < 0) {
                fatal(MYNAME ":Can't init %s\n", fname);
        }
@@ -120,6 +134,15 @@ waypt_read(void)
        int i,n;
        GPS_PWay *way;
 
+       if (getposn) {
+               waypoint *wpt = waypt_new();
+               wpt->latitude = gps_save_lat;
+               wpt->longitude = gps_save_lon;
+               wpt->shortname = "Position";
+               waypt_add(wpt);
+               return;
+       }
+
        if ((n = GPS_Command_Get_Waypoint(portname, &way)) < 0) {
                fatal(MYNAME  ":Can't get waypoint from %s\n", portname);
        }
@@ -279,6 +302,10 @@ route_read(void)
 static void
 data_read(void)
 {
+       if (poweroff) {
+               return;
+       }
+
        switch(global_opts.objective) {
                case trkdata: 
                        track_read();
@@ -514,6 +541,9 @@ track_write(void)
 static void
 data_write()
 {
+       if (poweroff) {
+               return;
+       }
        switch(global_opts.objective) {
                case wptdata:
                        waypoint_write();
@@ -536,5 +566,5 @@ ff_vecs_t garmin_vecs = {
        rw_deinit,
        data_read,
        data_write,
-       NULL
+       garmin_args
 };
index 7ac611aea777fdeee4156c57cd2d859f76eef0e1..235a5c4ea4999aeec92c6ac1f6579fb6478e4625 100644 (file)
@@ -39,6 +39,8 @@ int32 GPS_Command_Off(const char *port)
     GPS_PPacket tra;
     GPS_PPacket rec;
 
+    GPS_Util_Little();
+
     if(!GPS_Serial_On(port, &fd))
        return gps_errno;
 
@@ -46,8 +48,9 @@ int32 GPS_Command_Off(const char *port)
        return MEMORY_ERROR;
 
     GPS_Util_Put_Short(data,COMMAND_ID[gps_device_command].Cmnd_Turn_Off_Pwr);
-    
-    GPS_Make_Packet(&tra, LINK_ID[gps_link_type].Pid_Command_Data,
+   
+    /* robertl - LINK_ID isn't set yet.  Hardcode it to Garmin spec value */ 
+    GPS_Make_Packet(&tra, 10, /* LINK_ID[gps_link_type].Pid_Command_Data, */
                    data,2);
     if(!GPS_Write_Packet(fd,tra))
        return gps_errno;